package com.whu.waterworks.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.dto.StationAllDataDto;
import com.whu.waterworks.model.Realtimedata;
import com.whu.waterworks.model.Stationnumposition;
import com.whu.waterworks.service.DataService;
import com.whu.waterworks.service.StationnumpositionService;

/**
 * 得到管网实时信息
 * @author wangying
 *
 */
public class GetRealStationDataAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String waterPlantCode;//水厂编码
	private StationnumpositionService stationnumpositionService;
	private DataService dataService;
	private List<StationAllDataDto> allDataDtos;
	
	public String getAllStationData()
	{
		allDataDtos = new ArrayList<>();
		System.out.println("GetRealStationDataAction waterPlantCode="+waterPlantCode);
		List<Stationnumposition> stationnumpositions = stationnumpositionService.findAll(waterPlantCode);
		//System.out.println("GetRealStationDataAction stationnumpositions.size()="+stationnumpositions.size());
		
		try {
			if(stationnumpositions!=null && stationnumpositions.size()>0)
			{
				for(Stationnumposition stationnumposition:stationnumpositions)
				{
					System.out.println("GetRealStationDataAction stationnumposition="+stationnumposition.getStationnum());
					StationAllDataDto stationAllDataDto = new StationAllDataDto();
						List<Realtimedata> realtimedatas = dataService.getAllRealTimeDataById(stationnumposition.getStationnum());
						if(realtimedatas!=null && realtimedatas.size()>0)
						{
							//每个站点的所有类型数据
							for(Realtimedata realtimedata:realtimedatas)
							{
								stationAllDataDto.setStationnum(stationnumposition.getPositionname());
								if(realtimedata.getId().getType().contains("流量"))
								{
									stationAllDataDto.setFlowValue(realtimedata.getValue());
								}
								else if(realtimedata.getId().getType().contains("压力"))
								{
									stationAllDataDto.setPressureValue(realtimedata.getValue());
								}
								else if(realtimedata.getId().getType().contains("浊度"))
								{
									stationAllDataDto.setTurbidityValue(realtimedata.getValue());
								}
								else if(realtimedata.getId().getType().contains("余氯"))
								{
									stationAllDataDto.setChlorineValue(realtimedata.getValue());
								}
							}
							allDataDtos.add(stationAllDataDto);
						}
							
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return SUCCESS;
	}

	public String getWaterPlantCode() {
		return waterPlantCode;
	}

	public void setWaterPlantCode(String waterPlantCode) {
		this.waterPlantCode = waterPlantCode;
	}

	public StationnumpositionService getStationnumpositionService() {
		return stationnumpositionService;
	}

	public void setStationnumpositionService(StationnumpositionService stationnumpositionService) {
		this.stationnumpositionService = stationnumpositionService;
	}

	public DataService getDataService() {
		return dataService;
	}

	public void setDataService(DataService dataService) {
		this.dataService = dataService;
	}

	public List<StationAllDataDto> getAllDataDtos() {
		return allDataDtos;
	}

	public void setAllDataDtos(List<StationAllDataDto> allDataDtos) {
		this.allDataDtos = allDataDtos;
	}

	

}
